﻿using System;
using System.Windows.Forms;
using Complaint.Common;

namespace Complaint.PasswordHasher
{
    public partial class Form1 : Form
    {
        private string _salt;

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(textBox1.Text))
            {
                lblMessage.Text = "Please enter a password";
            }
            else
            {
                _salt = CryptoUtility.CreateSalt(5);
                var password = textBox1.Text;
                var hashedPassword = CryptoUtility.CreatePasswordHash(password, _salt);
                lblMessage.Text = hashedPassword;
                textBox2.Text = _salt;
                Clipboard.SetDataObject(hashedPassword, true);
            }
            lblMessage.Visible = true;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(textBox2.Text))
            {
                lblVerify.Text = "Please enter the original password";
            }
            else
            {
                var pwd = textBox2.Text;
                var hashedPwd = CryptoUtility.CreatePasswordHash(pwd, _salt);
                lblVerify.Text = lblMessage.Text.Equals(hashedPwd) ? "True" : "False";
            }
            lblVerify.Visible = true;
        }
    }
}
